package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.BladeVisualCategory;
import com.xjgzinfo.usdp.repository.BladeVisualCategoryRepository;
import com.xjgzinfo.usdp.service.BladeVisualCategoryService;
import com.xjgzinfo.usdp.service.dto.BladeVisualCategoryDTO;
import com.xjgzinfo.usdp.service.mapper.BladeVisualCategoryMapper;
import com.xjgzinfo.usdp.service.dto.BladeVisualCategoryCriteria;
import com.xjgzinfo.usdp.service.BladeVisualCategoryQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link BladeVisualCategoryResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class BladeVisualCategoryResourceIT {

    private static final String DEFAULT_CATEGORY_KEY = "AAAAAAAAAA";
    private static final String UPDATED_CATEGORY_KEY = "BBBBBBBBBB";

    private static final String DEFAULT_CATEGORY_VALUE = "AAAAAAAAAA";
    private static final String UPDATED_CATEGORY_VALUE = "BBBBBBBBBB";

    private static final Integer DEFAULT_IS_DELETED = 10;
    private static final Integer UPDATED_IS_DELETED = 9;
    private static final Integer SMALLER_IS_DELETED = 10 - 1;

    @Autowired
    private BladeVisualCategoryRepository bladeVisualCategoryRepository;

    @Autowired
    private BladeVisualCategoryMapper bladeVisualCategoryMapper;

    @Autowired
    private BladeVisualCategoryService bladeVisualCategoryService;

    @Autowired
    private BladeVisualCategoryQueryService bladeVisualCategoryQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restBladeVisualCategoryMockMvc;

    private BladeVisualCategory bladeVisualCategory;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static BladeVisualCategory createEntity(EntityManager em) {
        BladeVisualCategory bladeVisualCategory = new BladeVisualCategory()
            .categoryKey(DEFAULT_CATEGORY_KEY)
            .categoryValue(DEFAULT_CATEGORY_VALUE)
            .isDeleted(DEFAULT_IS_DELETED);
        return bladeVisualCategory;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static BladeVisualCategory createUpdatedEntity(EntityManager em) {
        BladeVisualCategory bladeVisualCategory = new BladeVisualCategory()
            .categoryKey(UPDATED_CATEGORY_KEY)
            .categoryValue(UPDATED_CATEGORY_VALUE)
            .isDeleted(UPDATED_IS_DELETED);
        return bladeVisualCategory;
    }

    @BeforeEach
    public void initTest() {
        bladeVisualCategory = createEntity(em);
    }

    @Test
    @Transactional
    public void createBladeVisualCategory() throws Exception {
        int databaseSizeBeforeCreate = bladeVisualCategoryRepository.findAll().size();
        // Create the BladeVisualCategory
        BladeVisualCategoryDTO bladeVisualCategoryDTO = bladeVisualCategoryMapper.toDto(bladeVisualCategory);
        restBladeVisualCategoryMockMvc.perform(post("/api/blade-visual-categories").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(bladeVisualCategoryDTO)))
            .andExpect(status().isCreated());

        // Validate the BladeVisualCategory in the database
        List<BladeVisualCategory> bladeVisualCategoryList = bladeVisualCategoryRepository.findAll();
        assertThat(bladeVisualCategoryList).hasSize(databaseSizeBeforeCreate + 1);
        BladeVisualCategory testBladeVisualCategory = bladeVisualCategoryList.get(bladeVisualCategoryList.size() - 1);
        assertThat(testBladeVisualCategory.getCategoryKey()).isEqualTo(DEFAULT_CATEGORY_KEY);
        assertThat(testBladeVisualCategory.getCategoryValue()).isEqualTo(DEFAULT_CATEGORY_VALUE);
        assertThat(testBladeVisualCategory.getIsDeleted()).isEqualTo(DEFAULT_IS_DELETED);
    }

    @Test
    @Transactional
    public void createBladeVisualCategoryWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = bladeVisualCategoryRepository.findAll().size();

        // Create the BladeVisualCategory with an existing ID
        bladeVisualCategory.setId(1L);
        BladeVisualCategoryDTO bladeVisualCategoryDTO = bladeVisualCategoryMapper.toDto(bladeVisualCategory);

        // An entity with an existing ID cannot be created, so this API call must fail
        restBladeVisualCategoryMockMvc.perform(post("/api/blade-visual-categories").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(bladeVisualCategoryDTO)))
            .andExpect(status().isBadRequest());

        // Validate the BladeVisualCategory in the database
        List<BladeVisualCategory> bladeVisualCategoryList = bladeVisualCategoryRepository.findAll();
        assertThat(bladeVisualCategoryList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkIsDeletedIsRequired() throws Exception {
        int databaseSizeBeforeTest = bladeVisualCategoryRepository.findAll().size();
        // set the field null
        bladeVisualCategory.setIsDeleted(null);

        // Create the BladeVisualCategory, which fails.
        BladeVisualCategoryDTO bladeVisualCategoryDTO = bladeVisualCategoryMapper.toDto(bladeVisualCategory);


        restBladeVisualCategoryMockMvc.perform(post("/api/blade-visual-categories").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(bladeVisualCategoryDTO)))
            .andExpect(status().isBadRequest());

        List<BladeVisualCategory> bladeVisualCategoryList = bladeVisualCategoryRepository.findAll();
        assertThat(bladeVisualCategoryList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategories() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(bladeVisualCategory.getId().intValue())))
            .andExpect(jsonPath("$.[*].categoryKey").value(hasItem(DEFAULT_CATEGORY_KEY)))
            .andExpect(jsonPath("$.[*].categoryValue").value(hasItem(DEFAULT_CATEGORY_VALUE)))
            .andExpect(jsonPath("$.[*].isDeleted").value(hasItem(DEFAULT_IS_DELETED)));
    }
    
    @Test
    @Transactional
    public void getBladeVisualCategory() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get the bladeVisualCategory
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories/{id}", bladeVisualCategory.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(bladeVisualCategory.getId().intValue()))
            .andExpect(jsonPath("$.categoryKey").value(DEFAULT_CATEGORY_KEY))
            .andExpect(jsonPath("$.categoryValue").value(DEFAULT_CATEGORY_VALUE))
            .andExpect(jsonPath("$.isDeleted").value(DEFAULT_IS_DELETED));
    }


    @Test
    @Transactional
    public void getBladeVisualCategoriesByIdFiltering() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        Long id = bladeVisualCategory.getId();

        defaultBladeVisualCategoryShouldBeFound("id.equals=" + id);
        defaultBladeVisualCategoryShouldNotBeFound("id.notEquals=" + id);

        defaultBladeVisualCategoryShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultBladeVisualCategoryShouldNotBeFound("id.greaterThan=" + id);

        defaultBladeVisualCategoryShouldBeFound("id.lessThanOrEqual=" + id);
        defaultBladeVisualCategoryShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryKeyIsEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryKey equals to DEFAULT_CATEGORY_KEY
        defaultBladeVisualCategoryShouldBeFound("categoryKey.equals=" + DEFAULT_CATEGORY_KEY);

        // Get all the bladeVisualCategoryList where categoryKey equals to UPDATED_CATEGORY_KEY
        defaultBladeVisualCategoryShouldNotBeFound("categoryKey.equals=" + UPDATED_CATEGORY_KEY);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryKeyIsNotEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryKey not equals to DEFAULT_CATEGORY_KEY
        defaultBladeVisualCategoryShouldNotBeFound("categoryKey.notEquals=" + DEFAULT_CATEGORY_KEY);

        // Get all the bladeVisualCategoryList where categoryKey not equals to UPDATED_CATEGORY_KEY
        defaultBladeVisualCategoryShouldBeFound("categoryKey.notEquals=" + UPDATED_CATEGORY_KEY);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryKeyIsInShouldWork() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryKey in DEFAULT_CATEGORY_KEY or UPDATED_CATEGORY_KEY
        defaultBladeVisualCategoryShouldBeFound("categoryKey.in=" + DEFAULT_CATEGORY_KEY + "," + UPDATED_CATEGORY_KEY);

        // Get all the bladeVisualCategoryList where categoryKey equals to UPDATED_CATEGORY_KEY
        defaultBladeVisualCategoryShouldNotBeFound("categoryKey.in=" + UPDATED_CATEGORY_KEY);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryKeyIsNullOrNotNull() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryKey is not null
        defaultBladeVisualCategoryShouldBeFound("categoryKey.specified=true");

        // Get all the bladeVisualCategoryList where categoryKey is null
        defaultBladeVisualCategoryShouldNotBeFound("categoryKey.specified=false");
    }
                @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryKeyContainsSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryKey contains DEFAULT_CATEGORY_KEY
        defaultBladeVisualCategoryShouldBeFound("categoryKey.contains=" + DEFAULT_CATEGORY_KEY);

        // Get all the bladeVisualCategoryList where categoryKey contains UPDATED_CATEGORY_KEY
        defaultBladeVisualCategoryShouldNotBeFound("categoryKey.contains=" + UPDATED_CATEGORY_KEY);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryKeyNotContainsSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryKey does not contain DEFAULT_CATEGORY_KEY
        defaultBladeVisualCategoryShouldNotBeFound("categoryKey.doesNotContain=" + DEFAULT_CATEGORY_KEY);

        // Get all the bladeVisualCategoryList where categoryKey does not contain UPDATED_CATEGORY_KEY
        defaultBladeVisualCategoryShouldBeFound("categoryKey.doesNotContain=" + UPDATED_CATEGORY_KEY);
    }


    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryValueIsEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryValue equals to DEFAULT_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldBeFound("categoryValue.equals=" + DEFAULT_CATEGORY_VALUE);

        // Get all the bladeVisualCategoryList where categoryValue equals to UPDATED_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldNotBeFound("categoryValue.equals=" + UPDATED_CATEGORY_VALUE);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryValueIsNotEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryValue not equals to DEFAULT_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldNotBeFound("categoryValue.notEquals=" + DEFAULT_CATEGORY_VALUE);

        // Get all the bladeVisualCategoryList where categoryValue not equals to UPDATED_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldBeFound("categoryValue.notEquals=" + UPDATED_CATEGORY_VALUE);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryValueIsInShouldWork() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryValue in DEFAULT_CATEGORY_VALUE or UPDATED_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldBeFound("categoryValue.in=" + DEFAULT_CATEGORY_VALUE + "," + UPDATED_CATEGORY_VALUE);

        // Get all the bladeVisualCategoryList where categoryValue equals to UPDATED_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldNotBeFound("categoryValue.in=" + UPDATED_CATEGORY_VALUE);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryValueIsNullOrNotNull() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryValue is not null
        defaultBladeVisualCategoryShouldBeFound("categoryValue.specified=true");

        // Get all the bladeVisualCategoryList where categoryValue is null
        defaultBladeVisualCategoryShouldNotBeFound("categoryValue.specified=false");
    }
                @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryValueContainsSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryValue contains DEFAULT_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldBeFound("categoryValue.contains=" + DEFAULT_CATEGORY_VALUE);

        // Get all the bladeVisualCategoryList where categoryValue contains UPDATED_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldNotBeFound("categoryValue.contains=" + UPDATED_CATEGORY_VALUE);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByCategoryValueNotContainsSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where categoryValue does not contain DEFAULT_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldNotBeFound("categoryValue.doesNotContain=" + DEFAULT_CATEGORY_VALUE);

        // Get all the bladeVisualCategoryList where categoryValue does not contain UPDATED_CATEGORY_VALUE
        defaultBladeVisualCategoryShouldBeFound("categoryValue.doesNotContain=" + UPDATED_CATEGORY_VALUE);
    }


    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted equals to DEFAULT_IS_DELETED
        defaultBladeVisualCategoryShouldBeFound("isDeleted.equals=" + DEFAULT_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted equals to UPDATED_IS_DELETED
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.equals=" + UPDATED_IS_DELETED);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsNotEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted not equals to DEFAULT_IS_DELETED
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.notEquals=" + DEFAULT_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted not equals to UPDATED_IS_DELETED
        defaultBladeVisualCategoryShouldBeFound("isDeleted.notEquals=" + UPDATED_IS_DELETED);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsInShouldWork() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted in DEFAULT_IS_DELETED or UPDATED_IS_DELETED
        defaultBladeVisualCategoryShouldBeFound("isDeleted.in=" + DEFAULT_IS_DELETED + "," + UPDATED_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted equals to UPDATED_IS_DELETED
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.in=" + UPDATED_IS_DELETED);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsNullOrNotNull() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted is not null
        defaultBladeVisualCategoryShouldBeFound("isDeleted.specified=true");

        // Get all the bladeVisualCategoryList where isDeleted is null
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.specified=false");
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted is greater than or equal to DEFAULT_IS_DELETED
        defaultBladeVisualCategoryShouldBeFound("isDeleted.greaterThanOrEqual=" + DEFAULT_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted is greater than or equal to (DEFAULT_IS_DELETED + 1)
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.greaterThanOrEqual=" + (DEFAULT_IS_DELETED + 1));
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted is less than or equal to DEFAULT_IS_DELETED
        defaultBladeVisualCategoryShouldBeFound("isDeleted.lessThanOrEqual=" + DEFAULT_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted is less than or equal to SMALLER_IS_DELETED
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.lessThanOrEqual=" + SMALLER_IS_DELETED);
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsLessThanSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted is less than DEFAULT_IS_DELETED
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.lessThan=" + DEFAULT_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted is less than (DEFAULT_IS_DELETED + 1)
        defaultBladeVisualCategoryShouldBeFound("isDeleted.lessThan=" + (DEFAULT_IS_DELETED + 1));
    }

    @Test
    @Transactional
    public void getAllBladeVisualCategoriesByIsDeletedIsGreaterThanSomething() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        // Get all the bladeVisualCategoryList where isDeleted is greater than DEFAULT_IS_DELETED
        defaultBladeVisualCategoryShouldNotBeFound("isDeleted.greaterThan=" + DEFAULT_IS_DELETED);

        // Get all the bladeVisualCategoryList where isDeleted is greater than SMALLER_IS_DELETED
        defaultBladeVisualCategoryShouldBeFound("isDeleted.greaterThan=" + SMALLER_IS_DELETED);
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultBladeVisualCategoryShouldBeFound(String filter) throws Exception {
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(bladeVisualCategory.getId().intValue())))
            .andExpect(jsonPath("$.[*].categoryKey").value(hasItem(DEFAULT_CATEGORY_KEY)))
            .andExpect(jsonPath("$.[*].categoryValue").value(hasItem(DEFAULT_CATEGORY_VALUE)))
            .andExpect(jsonPath("$.[*].isDeleted").value(hasItem(DEFAULT_IS_DELETED)));

        // Check, that the count call also returns 1
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultBladeVisualCategoryShouldNotBeFound(String filter) throws Exception {
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingBladeVisualCategory() throws Exception {
        // Get the bladeVisualCategory
        restBladeVisualCategoryMockMvc.perform(get("/api/blade-visual-categories/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateBladeVisualCategory() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        int databaseSizeBeforeUpdate = bladeVisualCategoryRepository.findAll().size();

        // Update the bladeVisualCategory
        BladeVisualCategory updatedBladeVisualCategory = bladeVisualCategoryRepository.findById(bladeVisualCategory.getId()).get();
        // Disconnect from session so that the updates on updatedBladeVisualCategory are not directly saved in db
        em.detach(updatedBladeVisualCategory);
        updatedBladeVisualCategory
            .categoryKey(UPDATED_CATEGORY_KEY)
            .categoryValue(UPDATED_CATEGORY_VALUE)
            .isDeleted(UPDATED_IS_DELETED);
        BladeVisualCategoryDTO bladeVisualCategoryDTO = bladeVisualCategoryMapper.toDto(updatedBladeVisualCategory);

        restBladeVisualCategoryMockMvc.perform(put("/api/blade-visual-categories").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(bladeVisualCategoryDTO)))
            .andExpect(status().isOk());

        // Validate the BladeVisualCategory in the database
        List<BladeVisualCategory> bladeVisualCategoryList = bladeVisualCategoryRepository.findAll();
        assertThat(bladeVisualCategoryList).hasSize(databaseSizeBeforeUpdate);
        BladeVisualCategory testBladeVisualCategory = bladeVisualCategoryList.get(bladeVisualCategoryList.size() - 1);
        assertThat(testBladeVisualCategory.getCategoryKey()).isEqualTo(UPDATED_CATEGORY_KEY);
        assertThat(testBladeVisualCategory.getCategoryValue()).isEqualTo(UPDATED_CATEGORY_VALUE);
        assertThat(testBladeVisualCategory.getIsDeleted()).isEqualTo(UPDATED_IS_DELETED);
    }

    @Test
    @Transactional
    public void updateNonExistingBladeVisualCategory() throws Exception {
        int databaseSizeBeforeUpdate = bladeVisualCategoryRepository.findAll().size();

        // Create the BladeVisualCategory
        BladeVisualCategoryDTO bladeVisualCategoryDTO = bladeVisualCategoryMapper.toDto(bladeVisualCategory);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restBladeVisualCategoryMockMvc.perform(put("/api/blade-visual-categories").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(bladeVisualCategoryDTO)))
            .andExpect(status().isBadRequest());

        // Validate the BladeVisualCategory in the database
        List<BladeVisualCategory> bladeVisualCategoryList = bladeVisualCategoryRepository.findAll();
        assertThat(bladeVisualCategoryList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteBladeVisualCategory() throws Exception {
        // Initialize the database
        bladeVisualCategoryRepository.saveAndFlush(bladeVisualCategory);

        int databaseSizeBeforeDelete = bladeVisualCategoryRepository.findAll().size();

        // Delete the bladeVisualCategory
        restBladeVisualCategoryMockMvc.perform(delete("/api/blade-visual-categories/{id}", bladeVisualCategory.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<BladeVisualCategory> bladeVisualCategoryList = bladeVisualCategoryRepository.findAll();
        assertThat(bladeVisualCategoryList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
